<template>
  <a-card class="hot-news">
    <h3 class="hot-title">热门新闻</h3>
    <ul class="hot-list" v-if="!!hotNews && hotNews.length > 0">
      <li class="hot-list-item" v-for="(item, index) in hotNews" :key="index">
        <span class="num-top">{{ index + 1 }}</span>
        <p>
          <router-link :to="`/news/detail/${item.id}`">{{ item.title }}</router-link>
          <span class="hot-date">{{ item.publishTime }}</span>
        </p>
      </li>
    </ul>
    <EmptyData v-else>暂无数据</EmptyData>
  </a-card>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { listHotNews } from "@/api/news";
import EmptyData from "@/components/public/EmptyData.vue";

const hotNews = ref([]);

onMounted(() => {
  getHotNewsList();
});

async function getHotNewsList() {
  let params = {
    pageNo: 1,
    pageSize: 5
  };
  const res: any = await listHotNews(params);
  hotNews.value = res.result?.records;
}
</script>
<style lang="less" scoped>
@hover_color: #3370ff;

.hot-news {
  width: 300px;
  min-height: 280px;
  box-sizing: border-box;
  margin-bottom: 50px;
  height: fit-content;
  margin-top:65px;
}

.hot-title {
  font-weight: 600;
  text-align: center;
  font-size: 16px;
  height: 58px;
  line-height: 58px;
  border-bottom: 1px dashed #e6e8eb;
}

.hot-list {
  padding: 18px 5px 0;

  :first-child .num-top {
    background-color: #f84521
  }

  :nth-child(2) .num-top {
    background-color: #ff6f24;
  }

  :nth-child(3) .num-top {
    background-color: #ff8c25;
  }
}

.num-top {
  position: absolute;
  left: 0;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 2px;
  color: #fff;
  background-color: #ababab;
  display: block;
  text-align: center;
  line-height: 16px;
  font-size: 12px;
}

.hot-list-item {
  position: relative;
  cursor: pointer;
  padding: 0 0 20px;

  p {
    margin-left: 24px;
  }

  a {
    color: rgba(0, 0, 0, 1);
    transition: color .3s;
    width: 230px;
    line-height: 22px;
    font-size: 14px;
    overflow: hidden;
    //white-space: pre-wrap;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  a:hover {
    color: @hover_color;
  }

  .hot-date {
    display: block;
    color: #b8b8b8;
    font-size: 14px;
    padding-top: 5px;
    line-height: 16px;
    white-space: nowrap;
  }
}

.hot-list-item:after {
  content: "";
  display: block;
  width: 230px;
  position: absolute;
  bottom: 10px;
  left: 24px;
  border-bottom: 1px dashed #e6e8eb;
}

.hot-list-item:last-of-type:after {
  content: none;
}

:deep(.ant-card__body) {
  padding-top: 0;
}
</style>
